const User = require('../models/user');
module.exports = (req, res, next) => {

    if (req.remoteUser) {
        res.locals.user = req.remoteUser;
    }
    // 从会话中取出已登录用户得ID
    const uid = req.session.uid;
    if (!uid) return next();
    // 从Redis中取出已登录用户得数据
    User.get(uid, (err, user) => {
        if (err) return next(err);
        // 将用户数据输出到响应对象中
        req.user = res.locals.user = user;
        next();
    })
}